<template>
	<view>
		<view class="box">
			<view class="list">
				<p>
					银行名称：
				</p>
				<input type="text" v-model="data.bank_name" placeholder="银行" >
			</view>
			
			<view class="list">
				<p>
					姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：
				</p>
				<input type="text" v-model="data.username" placeholder="请输入姓名" >
			</view>
			
			<view class="list">
				<p>
					银行卡号：
				</p>
				<input type="text" v-model="data.bank_code" placeholder="请输入银行卡号" >
			</view>
			
			<view class="list">
				<p>
					开&nbsp;户&nbsp;行：
				</p>
				<input type="text" v-model="data.bank_deposit" placeholder="请输入开户行" >
			</view>
			<view style="margin-top: 40px;">
				<button v-if="title=='修改'" @click="bank_edit()">保存</button>
				<button v-if="title=='新增'" @click="bank_add()">保存</button>
			</view>

		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				title:"修改",
				data:{
					username: "", //开户名称
					bank_name: "", //银行名称
					bank_code: "", // 银行卡号
					bank_deposit: "", //开户行
					id:""
				}
			}
		},
		onLoad(open)
		{
			if(open.data=="")
			{
				this.title = "新增";
				uni.setNavigationBarTitle({
					title:"新增"
				}); 
			}else{
				//字符串转json
				var jsonObj = JSON.parse(open.data);//将JSON字符串转换为JSON对象
				this.data = jsonObj;
			}
			console.log(open)
		},
		methods: {
			//添加银行卡
			bank_add()
			{
				let data = {
								"username": this.data.username,
								"bank_name": this.data.bank_name,
								"bank_code": this.data.bank_code,
								"bank_deposit": this.data.bank_deposit
							}
					this.$rqt.bank_add(data).then(res => {
						console.log(res);
						uni.showToast({
							title: res.msg,
							icon: "success",
							duration: 850
						});
						setTimeout(()=>{
							uni.navigateBack({
								delta:1,//返回层数，2则上上页
							})
						},850);

					})
			},
			//修改银行卡
			bank_edit()
			{
				let data = {
								"id":this.data.id,
								"username": this.data.username,
								"bank_name": this.data.bank_name,
								"bank_code": this.data.bank_code,
								"bank_deposit": this.data.bank_deposit
							}
				this.$rqt.bank_edit(data).then(res => {
					console.log(res);
					uni.showToast({
						title: res.msg,
						icon: "success",
						duration: 850
					});
						setTimeout(()=>{
							uni.navigateBack({
								delta:1,//返回层数，2则上上页
							})
						},850);
				})
			}
		}
	}
</script>

<style scoped>
	.box>view>button{
		color: #fff;
		font-size: 18px;
		width: 90%;
		margin: 0 auto;
		height: 50px;
		font-weight: 600;
		background: #1890FF;
		box-shadow: 0px 0px 4px 0px rgba(204,204,204,0.5);
		border-radius: 25px;
	}
	.list{
		height: 50px;
		line-height: 50px;
		display: flex;
		align-items:center;
	}
	.list>p{
		width:100px;
		font-size: 18px;
		font-weight: 500;
	}
	.list>input{
		width: 80%;
		line-height: 50px;
		height: 50px;
		border-bottom: 1px solid #EEEEEE;
	}
.box{
	overflow: hidden;
	padding-top: 20px;
	width: 90%;
	margin: 0 auto;
}
</style>
